#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

bool cmp(std::pair<int, int> a, std::pair<int, int> b)
{
    if (a.first < b.first)
    {
        return true;
    }
    return false;
}

int parseStr(std::string istr, std::vector<std::pair<int, int>> &wl)
{
    std::istringstream ss(istr);
    std::string token;
    while (std::getline(ss, token, ','))
    {
        int idx = token.find('-');
        if (idx != std::string::npos)
        {
            int start = std::stoi(token.substr(0, idx));
            int end = std::stoi(token.substr(idx + 1));
            wl.push_back({start, end});
        }
        else
        {
            int start = std::stoi(token);
            int end = start;
            wl.push_back({start, end});
        }
    }

    return 0;
}

int main()
{
    std::string istr;
    std::cin >> istr;

    std::vector<std::pair<int, int>> wl;
    parseStr(istr, wl);

    int k;
    std::cin >> k;
    for (int i = 0; i < wl.size(); i++)
    {
        if (wl[i].first <= k && wl[i].second >= k)
        {
            if (wl[i].first == k && wl[i].second == k)
            {
                wl.erase(wl.begin() + i);
            }
            else if (wl[i].first == k && wl[i].second != k)
            {
                wl[i].first++;
            }
            else if (wl[i].first != k && wl[i].second == k)
            {
                wl[i].second--;
            }
            else
            {
                wl.push_back({k + 1, wl[i].second});
                wl[i].second = k - 1;
            }
            break;
        }
    }

    std::sort(wl.begin(), wl.end(), cmp);

    for (int i = 0; i < wl.size(); i++)
    {
        if (i != wl.size() - 1)
        {
            if (wl[i].first == wl[i].second)
            {
                std::cout << wl[i].first << ",";
            }
            else
            {
                std::cout << wl[i].first << "-" << wl[i].second << ",";
            }
        }
        else
        {
            if (wl[i].first == wl[i].second)
            {
                std::cout << wl[i].first << std::endl;
            }
            else
            {
                std::cout << wl[i].first << "-" << wl[i].second << std::endl;
            }
        }
    }

    return 0;
}